﻿using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;

namespace YArchitech.Revit
{
	public class ElectricSwitchBoxesContainUsersFilter : ISelectionFilter
	{
		bool ISelectionFilter.AllowElement(Element elem)
		{
			return ElectricSwitchBoxesContainUsersFilter.IsValidSwitchBoxes(elem);
		}

		bool ISelectionFilter.AllowReference(Reference reference, XYZ position)
		{
			return false;
		}

		public static bool IsValidSwitchBoxes(Element elem)
		{
			try
			{
				if (elem is FamilyInstance && elem.Category.Id.IntegerValue == -2001040)
				{
					FamilySymbol fs = elem.Document.GetElement(elem.GetTypeId()) as FamilySymbol;
					if (fs.GetFamilyNameBySymbol().Contains("配电柜") || fs.GetFamilyNameBySymbol() == "直流信号屏")
					{
						return true;
					}
				}
			}
			catch (Exception ex)
			{
				string message = ex.Message;
			}
			return false;
		}
	}
}
